package com.fangque.kepp.framework.user;

import com.fangque.kepp.framework.user.entity.Menu;
import com.fangque.kepp.framework.user.entity.Role;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import java.util.ArrayList;
import java.util.List;

public class AuthoritiesUtil {

    public static List<GrantedAuthority> getAuthorities(List<Role> roles){
        List<GrantedAuthority> authorities = new ArrayList<>();
        if (roles == null) {
            return authorities;
        }
        for (Role role : roles) {
            List<Menu> menuList = role.getMenuList();
            if (menuList != null) {
                for (Menu menu : menuList) {
                    authorities.add(new SimpleGrantedAuthority(menu.getUrl()));
                }
            }
        }
        return authorities;
    }
}
